use serde::{Deserialize, Serialize};
use common::page::{BasePage, PageData};

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LetterPage {
    pub page_data: Option<PageData>,
}

impl BasePage for LetterPage {
    fn get_page_data(&self) -> PageData {
        match self.page_data.clone() {
            None => {
                PageData {
                    page: 1,
                    page_size: 10,
                    sorter: None,
                }
            }
            Some(page_data) => {
                page_data
            }
        }
    }
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MailItem {
    /**物品id*/
    pub item_id: u32,
    /**物品数量*/
    pub count: i32,
    /**物品类型*/
    pub item_type: u32,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SendMail {
    /**角色编号*/
    pub charac_no: i32,

    /**标题*/
    pub title: String,

    /**内容*/
    pub content: String,

    /**金币*/
    pub gold: u32,

    /**附件*/
    pub items: Vec<MailItem>,
}


pub enum ItemType {
    Equipment(u32, String),
    Consumables(u32, String),
    Material(u32, String),
    MissionMaterials(u32, String),
    Pet(u32, String),
    PetEquipment(u32, String),
    PetConsumables(u32, String),
    Fashion(u32, String),
    ExpertJob(u32, String),
    Other(u32, String),
}


impl From<u32> for ItemType {
    fn from(value: u32) -> Self {
        match value {
            1 => ItemType::Equipment(value, "装备".to_string()),
            2 => ItemType::Consumables(value, "消耗品".to_string()),
            3 => ItemType::Material(value, "材料".to_string()),
            4 => ItemType::MissionMaterials(value, "任务材料".to_string()),
            5 => ItemType::Pet(value, "宠物".to_string()),
            6 => ItemType::PetEquipment(value, "宠物装备".to_string()),
            7 => ItemType::PetConsumables(value, "宠物消耗品".to_string()),
            8 => ItemType::PetConsumables(value, "时装".to_string()),
            10 => ItemType::PetConsumables(value, "副职业".to_string()),
            _ => { ItemType::Other(value, "其他".to_string()) }
        }
    }
}

